﻿// (c) Copyright slimCODE Software Inc. - www.slimcode.com
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System;
using System.Collections.Generic;
using System.Text;
using SlimCode.Windows.Controls.Mobile;

namespace SlimCode.SlimPasswords
{
  class PasswordSymbolsOptionView : ItemView, IOptionView
  {
    private bool m_webSafeSymbols;
    private bool m_symbols;

    public PasswordSymbolsOptionView()
      : base( string.Empty, ContentAlignmentEx.MiddleLeft, 2 )
    {
      m_webSafeSymbols = Program.Settings.PasswordScheme.WebSafeSymbols;
      m_symbols = Program.Settings.PasswordScheme.Symbols;

      // We never know, with this poor design. :)
      if( m_webSafeSymbols && m_symbols )
      {
        System.Diagnostics.Debug.Fail( "Can't support both symbols. The 2nd includes the first." );
        m_symbols = false;
      }

      this.UpdateText();
    }

    private void UpdateText()
    {
      if( m_symbols )
      {
        this.Text = "Include special symbols";
      }
      else if( m_webSafeSymbols )
      {
        this.Text = "Include web-safe special symbols";
      }
      else
      {
        this.Text = "Do not include special symbols";
      }
    }

    #region IOptionView Members

    public void Apply()
    {
      Program.Settings.PasswordScheme.WebSafeSymbols = m_webSafeSymbols;
      Program.Settings.PasswordScheme.Symbols = m_symbols;
    }

    public void Cancel()
    {
    }

    public void OnClicked( SlimCode.Windows.Forms.Mobile.IScreenHost host, SlimCode.Windows.Forms.Mobile.IScreen screen )
    {
      bool webSafe = !m_webSafeSymbols && !m_symbols;
      m_symbols = m_webSafeSymbols;
      m_webSafeSymbols = webSafe;

      this.UpdateText();
    }

    #endregion
  }
}
